<?php
header("Content-type:text/html;charset=utf-8");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: *");
header("Access-Control-Allow-Headers: *");//这里“Access-Token”是我要传到后台的内容key
header("Access-Control-Expose-Headers: *");
error_reporting(0);
function return_data($flag,$msg,$data){
    $res = array("flag"=>$flag,"msg"=>$msg);
    if(!empty($data)){
        $res["data"] = $data;
    }
    $str = json_encode($res);
    return $str;
}
if($_SERVER['REQUEST_METHOD']=='OPTIONS'){
    echo return_data(false,"不支持OPTIONS请求","");
    return;
}
$fileIo = file_get_contents('php://input');
$param = json_decode($fileIo,true);
if($_GET['type'] == "0"){
    // 设置
    $url = $param['url'];
    $cdn = array(
        "cdn"=> $url
    );
    $cdnStr = '(function(){var c = "'.$url.'";if(window.initCdn){window.initCdn(c);}})()';
    file_put_contents("../cdn/cdn.js",$cdnStr);
    file_put_contents("../cdn.js",$cdnStr);
    file_put_contents("../../filePreview/cdn.js",$cdnStr);
    file_put_contents("../../filePreview/editer-service/cdn.js",$cdnStr);
    file_put_contents("../../customize/cdn.js",$cdnStr);
    file_put_contents("../../aliyunDrive/cdn.js",$cdnStr);
    file_put_contents("../../GameEmulator/cdn.js",$cdnStr);
    echo return_data(true,"设置成功",$url);
}else{
    echo return_data(false,"此方法暂不支持","");
}


